<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<%@ include file="/static/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width"/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>后台管理--菜单列表</title>
    <link href="${ctxStatic}/layui/css/layui.css" rel="stylesheet"/>
    <link href="${ctxStatic}/ligeruilib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css">
    <link href="${ctxStatic}/css/kpiui.css" rel="stylesheet"/>
    <script src="${ctxStatic}/js/jquery-1.8.3.min.js?v=2.0" type="text/javascript"></script>
    <script src="${ctxStatic}/layui/layui.all.js" type="text/javascript"></script>
    <script src="${ctxStatic}/ligeruilib/ligerUI/js/core/base.js" type="text/javascript"></script>
    <script src="${ctxStatic}/ligeruilib/ligerUI/js/plugins/ligerGrid.js" type="text/javascript"></script>
    <script src="${ctxStatic}/ligeruilib/ligerUI/js/plugins/ligerTree.js" type="text/javascript"></script>
    <script src="${ctxStatic}/ligeruilib/ligerUI/js/plugins/ligerComboBox.js" type="text/javascript"></script>
    <script src="${ctxStatic}/js/common.js" type="text/javascript"></script>
    <script src="${ctxStatic}/img/html2canvas-0.4.1.js" type="text/javascript"></script>
    <script src="${ctxStatic}/img/canvg2.js" type="text/javascript"></script>
    <script src="${ctxStatic}/img/jspdf.min.js" type="text/javascript"></script>


    <style>
        .pdf > table {
            width: 100%;
            font-size: .938em;
            border-collapse: collapse; /*边框会合并为一个单一的边框*/
        }

        .pdf th {
            text-align: left;
            padding: .5em .5em;
            font-weight: bold;
            background: #66677c;
            color: #fff;
        }

        .pdf td {
            padding: .5em .5em;
            border-bottom: solid 1px #ccc;
        }

        .pdf table, .pdf table tr th, .pdf table tr td {
            border: 1px solid #0094ff;
        }

        /*设置边框的*/
    </style>

</head>
<body>


<div class="serchcontent" style="margin:10px">
    <div class="search" style="    margin-top: 10px;   margin-left: 30px">
        <div class="layui-form">
            <table nostyle="true">
                <tr>
                    <td class="td_select">
                        <select id="year" placeholder="年份" lay-filter="year">
                            <option value="2025">2025年</option>
                            <option value="2024">2024年</option>
                            <option value="2023">2023年</option>
                            <option value="2022">2022年</option>
                            <option value="2021">2021年</option>
                            <option value="2020">2020年</option>
                            <option value="2019">2019年</option>
                            <option value="2018">2018年</option>
                            <option value="2017">2017年</option>
                        </select>
                        <input type="hidden" id="hidyear" value="${year}"/>
                    </td>
                    <td class="td_select">
                        <select id="month" lay-filter="month">

                            <option value="1">1月</option>
                            <option value="2">2月</option>
                            <option value="3">3月</option>
                            <option value="4">4月</option>
                            <option value="5">5月</option>
                            <option value="6">6月</option>
                            <option value="7">7月</option>
                            <option value="8">8月</option>
                            <option value="9">9月</option>
                            <option value="10">10月</option>
                            <option value="11">11月</option>
                            <option value="12">12月</option>
                        </select>
                        <input type="hidden" id="hidorgname" value="${orgname}">
                        <input type="hidden" id="hiddeptname" value="${deptName}">
                    </td>
                    <td>
                        <input type="button" class="button" value="查询" onclick="search()"/>
                        <button class="button" id="pdfbutton" style="display: none" onclick="createPdf()">重新生成公示</button>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>

<div class="content" style="margin-left: 20px">

    <table class="layui-table fc-view-container" lay-data="" lay-filter="attbmhzlist" id="attbmhzlist">
        <thead>
        <tr>
            <th lay-data="{field:'rowNum', width:60,align:'center',fixed: 'left'}" rowspan="2">序号</th>
            <th lay-data="{field:'realname', width:120,align:'center',fixed: 'left',templet: '#realnameTpl'}"
                rowspan="2">
                姓名
            </th>
            <th lay-data="{field:'cardno', width:200,align:'center',event:'glxs', style:'cursor: pointer;'}"
                rowspan="2">
                身份证号
            </th>
            <th lay-data="{field:'orgname', width:200,align:'center',event:'glxs', style:'cursor: pointer;'}"
                rowspan="2">
                实际工作单位
            </th>
            <th lay-data="{field:'rsgxorgname', width:200,align:'center',event:'glxs', style:'cursor: pointer;'}"
                rowspan="2">人事关系所在单位
            </th>
            <th lay-data="{field:'year', width:80,align:'center',event:'glxs', style:'cursor: pointer;'}" rowspan="2">年份
            </th>
            <th lay-data="{field:'mouth', width:80,align:'center',event:'glxs', style:'cursor: pointer;'}" rowspan="2">
                月份
            </th>

            <!--<th lay-data="{field:'sfqq', width:100,align:'center',event:'glxs', style:'cursor: pointer;'}" rowspan="2">是否全勤</th>-->
            <!--<th lay-data="{field:'jbts', width:100,align:'center',event:'glxs', style:'cursor: pointer;'}" rowspan="2">加班天数</th>  -->
            <th lay-data="{field:'sfjb', width:100,align:'center',templet: '#sfjbTpl'}" rowspan="2">是否加班</th>
            <th lay-data="{align:'center'}" colspan="10">未 出勤天数</th>
            <th lay-data="{field:'cdcc', width:80,align:'center',event:'glxs', style:'cursor: pointer;'}" rowspan="2">迟到
            </th>
            <th lay-data="{field:'ztcc', width:80,align:'center',event:'glxs', style:'cursor: pointer;'}" rowspan="2">早退
            </th>
            <th lay-data="{field:'kgcs', width:80,align:'center',event:'glxs', style:'cursor: pointer;'}" rowspan="2">旷工
            </th>
            <th lay-data="{field:'remark', width:120,align:'center',event:'glxs', style:'cursor: pointer;'}"
                rowspan="2">
                备注
            </th>
            <th lay-data="{field:'status', width:100,align:'center',event:'glxs', style:'cursor: pointer;'}"
                rowspan="2">
                状态
            </th>
            <th lay-data="{width: 100, align: 'center', toolbar: '#operate'}" rowspan="2">操作</th>
        </tr>
        <tr>
            <th lay-data="{field:'wcqtsxj', width:80,align:'center',templet: '#wcqtsxjTpl',event:'glxs', style:'cursor: pointer;'}">
                小计
            </th>
            <th lay-data="{field:'xjts', width:100,align:'center',templet: '#xjtsTpl',event:'glxs', style:'cursor: pointer;'}">
                年休假
            </th>
            <th lay-data="{field:'tqjts', width:100,align:'center',templet: '#tqjtsTpl',event:'glxs', style:'cursor: pointer;'}">
                探亲假
            </th>
            <th lay-data="{field:'hjts', width:80,align:'center',templet: '#hjtsTpl',event:'glxs', style:'cursor: pointer;'}">
                婚假
            </th>
            <th lay-data="{field:'syjts', width:100,align:'center',templet: '#syjtsTpl',event:'glxs', style:'cursor: pointer;'}">
                生育假
            </th>
            <th lay-data="{field:'sangjts', width:80,align:'center',templet: '#sangjtsTpl',event:'glxs', style:'cursor: pointer;'}">
                丧假
            </th>
            <th lay-data="{field:'gsts', width:100,align:'center',templet: '#gstsTpl',event:'glxs', style:'cursor: pointer;'}">
                因公致伤
            </th>
            <th lay-data="{field:'bjts', width:80,align:'center',templet: '#bjtsTpl',event:'glxs', style:'cursor: pointer;'}">
                病假
            </th>
            <th lay-data="{field:'sjts', width:80,align:'center',templet: '#sjtsTpl',event:'glxs', style:'cursor: pointer;'}">
                事假
            </th>
            <th lay-data="{field:'qtts', width:80,align:'center',templet: '#qttsTpl',event:'glxs', style:'cursor: pointer;'}">
                其他
            </th>
        </tr>
        </thead>
    </table>
    <script type="text/html" id="operate">

        <!--<img class="btn-img" src="${ctxStatic}/images/button/detail.png" lay-event="detail" alt="详情" title="详情">-->

        {{#  if(d.status == 0||d.status == 3){ }}
        <img class="btn-img" src="${ctxStatic}/images/index/btn_edit.png" lay-event="btntz" alt="调整考勤表" title="调整考勤表">
        {{#  } }}


    </script>

    <script type="text/html" id="realnameTpl">
        <span class="dbclickspan" ondblclick="OpenUserInfo({{ d.userid }},'{{ d.realname }}')"> {{ d.realname }}<span>
    </script>
    <script type="text/html" id="sfjbTpl">
        {{#  if(d.sfjb==0){ }}
        <span style="color: rgba(255,186,0,1);font-weight:bold;">否</span>
        {{#  } else { }}
        是
        {{#  } }}
    </script>

    <script type="text/html" id="wcqtsxjTpl">
        {{#  if(d.wcqtsxj>0){ }}
        <span style="color: rgba(255,186,0,1);font-weight:bold;">{{ d.wcqtsxj }}</span>
        {{#  } else { }}
        {{ d.wcqtsxj }}
        {{#  } }}
    </script>

    <script type="text/html" id="xjtsTpl">
        {{#  if(d.xjts>0){ }}
        <span style="color: rgba(255,186,0,1);font-weight:bold;">{{ d.xjts }}</span>
        {{#  } else { }}
        {{ d.xjts }}
        {{#  } }}
    </script>

    <script type="text/html" id="tqjtsTpl">
        {{#  if(d.tqjts>0){ }}
        <span style="color: rgba(255,186,0,1);font-weight:bold;">{{ d.tqjts }}</span>
        {{#  } else { }}
        {{ d.tqjts }}
        {{#  } }}
    </script>

    <script type="text/html" id="hjtsTpl">
        {{#  if(d.hjts>0){ }}
        <span style="color: rgba(255,186,0,1);font-weight:bold;">{{ d.hjts }}</span>
        {{#  } else { }}
        {{ d.hjts }}
        {{#  } }}
    </script>

    <script type="text/html" id="syjtsTpl">
        {{#  if(d.syjts>0){ }}
        <span style="color: rgba(255,186,0,1);font-weight:bold;">{{ d.syjts }}</span>
        {{#  } else { }}
        {{ d.syjts }}
        {{#  } }}
    </script>

    <script type="text/html" id="sangjtsTpl">
        {{#  if(d.sangjts>0){ }}
        <span style="color: rgba(255,186,0,1);font-weight:bold;">{{ d.sangjts }}</span>
        {{#  } else { }}
        {{ d.sangjts }}
        {{#  } }}
    </script>

    <script type="text/html" id="gstsTpl">
        {{#  if(d.gsts>0){ }}
        <span style="color: rgba(255,186,0,1);font-weight:bold;">{{ d.gsts }}</span>
        {{#  } else { }}
        {{ d.gsts }}
        {{#  } }}
    </script>

    <script type="text/html" id="bjtsTpl">
        {{#  if(d.bjts>0){ }}
        <span style="color: rgba(255,186,0,1);font-weight:bold;">{{ d.bjts }}</span>
        {{#  } else { }}
        {{ d.bjts }}
        {{#  } }}
    </script>

    <script type="text/html" id="sjtsTpl">
        {{#  if(d.sjts>0){ }}
        <span style="color: rgba(255,186,0,1);font-weight:bold;">{{ d.sjts }}</span>
        {{#  } else { }}
        {{ d.sjts }}
        {{#  } }}
    </script>

    <script type="text/html" id="qttsTpl">
        {{#  if(d.qtts>0){ }}
        <span style="color: rgba(255,186,0,1);font-weight:bold;">{{ d.qtts }}</span>
        {{#  } else { }}
        {{ d.qtts }}
        {{#  } }}
    </script>
</div>
<div class="bottom_tab" id="bottom_btns" style="display: block;">
    <input type="button" id="passbtn" class="button" style="display: none" value="通过" onclick="ok()"/>
    <input type="button" id="retbtn" class="button" style="display: none" value="驳回" onclick="reject()"/>
</div>

<div id="table" class="pdf" style="display: none">

    <div class="orgname" style="text-align: center"></div>
    <table id="tableData">
        <thead>

        <tr>
            <th rowspan="2">序号</th>
            <th rowspan="2" style="width: 50px">姓名</th>
            <th rowspan="2" style="width: 130px">身份证号</th>
            <th rowspan="2">实际工作单位</th>
            <th rowspan="2">人事关系所在单位</th>
            <th rowspan="2">年份</th>
            <th rowspan="2">月份</th>
            <th rowspan="2">是否加班</th>
            <th colspan="10" style="text-align: center">未出勤天数</th>
            <th rowspan="2">迟到</th>
            <th rowspan="2">早退</th>
            <th rowspan="2">矿工</th>
            <th rowspan="2">备注</th>


        </tr>
        <tr>

            <th>小计</th>
            <th>年休假</th>
            <th>探亲假</th>
            <th>婚假</th>
            <th>生育假</th>
            <th>丧假</th>
            <th>因公致伤</th>
            <th>病假</th>
            <th>事假</th>
            <th>其他</th>
        </tr>
        </thead>


    </table>

</div>
<!--  <div id="list" class="list" lay-filter="list"></div>-->


</div>


</div>
</body>
<script>
    var _table;
    var _form;
    var hidtablehight;
    $(function () {

        initForm();
        $('#year').val(new Date().getFullYear());
        var month = new Date().getMonth();
        $('#month').val(month);
        // var str = month + '月';
        _form.render('select');

        getData(function (data) {
            console.log(data.status);
            if(data.status == 4 || data.status == 2){
                $("#pdfbutton").show();
                $("#passbtn").hide();
                $("#retbtn").hide();
            }else if (data.status == 1){
                $('#pdfbutton').hide();
                $("#passbtn").show();
                $("#retbtn").show();
            }else{
                $('#pdfbutton').hide();
                $("#passbtn").hide();
                $("#retbtn").hide();
            }

            window.datas = data;
            initTable(data.year, data.month, data.orgid, data.orgsummaryid, $('#realname').val());
            testData();
        });
    })


    function titlefomart() {
        var html = "房山公安分局" + $('#hiddeptname').val();
        var month = $("#month").val();
        var year = $("#year").val();
        html += year + "年" + month + "月考勤"
        $('.orgname').html(html)
    }

    function initForm() {
        layui.use('form', function () {
            form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功


            form.render();
            _form = form;
        });
    }


    function testData() {
        var data = window.datas;
        $.ajax({
            type: "POST",
            url: "get_sh_list",
            data: {
                year: data.year ? data.year : '1990',
                mouth: data.month,
                orgid: data.orgid?data.orgid:'-1',
                orgsummaryid: data.orgsummaryid,
                realname: data.realname,
                page: 1,
                limit: 1000
            },
            beforeSend: function (XHR) {

            },
            success: function (data) {
                $("#tableData tbody").html("");
                data = eval('(' + data + ')').data;
                for (var i = 0; i < data.length; i++) {


                    var tr = "<tr><td>" + (i + 1) + "</td>";
                    tr += "<td>" + data[i].realname + "</td>";

                    tr += "<td>" + data[i].cardno + "</td>";
                    tr += "<td>" + data[i].orgname + "</td>";
                    tr += "<td>" + (data[i].rsgxorgname == null ? '' : data[i].rsgxorgname) + "</td>";
                    tr += "<td>" + data[i].year + "</td>";
                    tr += "<td>" + data[i].mouth + "</td>";
                    tr += "<td>" + (data[i].sfjb == 0 ? '否' : '是') + "</td>";
                    tr += "<td>" + data[i].wcqtsxj + "</td>";
                    tr += "<td>" + data[i].xjts + "</td>";
                    tr += "<td>" + data[i].tqjts + "</td>";
                    tr += "<td>" + data[i].hjts + "</td>";
                    tr += "<td>" + data[i].syjts + "</td>";
                    tr += "<td>" + data[i].sangjts + "</td>";
                    tr += "<td>" + data[i].gsts + "</td>";
                    tr += "<td>" + data[i].bjts + "</td>";
                    tr += "<td>" + data[i].sjts + "</td>";
                    tr += "<td>" + data[i].qtts + "</td>";
                    tr += "<td>" + data[i].cdcc + "</td>";
                    tr += "<td>" + data[i].ztcc + "</td>";
                    tr += "<td>" + data[i].kgcs + "</td>";
                    tr += "<td>" + (data[i].remark == null ? '' : data[i].remark) + "</td></tr>";


                    $('#tableData').append(tr);
                }
                // hidtablehight =  data.length * 70;

            },
            complete: function (XHR) {
                top.mylayui.closeAll('loading');
            },
            error: function () {

            }
        });


    }


    function initTable(year, month, orgid, orgsummaryid, realname) {
        layui.use('table', function () {
            table = layui.table;
            table.init('attbmhzlist', {
                height: $(window).height() - 100
                , url: 'get_sh_list ' // 数据接口
                , page: true // 开启分页
                , limit: 40
                , id: 'attbmhzlist'
                , limits: [20, 40, 80, 100]
                , method: "post"
                , request: {
                    type: 'post'
                }
                , where: {
                    //year: $("#detailyear").val(),
                    //mouth:$("#detailmonth").val(),
                    year: year ? year : '1990',
                    mouth: month ? month:'12',
                    orgid: orgid? orgid : '-1',
                    orgsummaryid: orgsummaryid,
                    realname: realname
                }
                , done: function (res, page, count) {

                    var dataarr = res.data;
                    $("[data-field='status']").children().each(function (index) {
                        if (index > 0) {
                            var text = $(this).text();
                            switch (text) {
                                case null:
                                    $(this).text("未填报");
                                    break;
                                case '':
                                    $(this).text("未填报");
                                    break;
                                case '0':
                                    $(this).text("填报");
                                    break;
                                case '1':
                                    $(this).text("提交");
                                    break;
                                case '4':
                                    $(this).text("已审批");
                                    break;
                                case '2':
                                    $(this).text("归档");
                                    break;
                                case '3':
                                    $(this).text("驳回");
                                    break;
                            }
                        }
                    })


                    $("[data-field='sfqq']").children().each(function (index) {
                        if (index > 0) {
                            var text = $(this).text();
                            if (text == "0") {
                                $(this).text("否");
                            }
                            else {
                                $(this).text("是");
                            }
                        }
                    })
                }
            });

            //监听工具条
            table.on('tool(attbmhzlist)', function (obj) {
                var data = obj.data;
                if (obj.event === 'detail') {
                    vAttBmHz.openadddetail(obj.data.attsummaryid, obj.data.orgsummaryid);
                } else if (obj.event === 'del') {

                    top.mylayui.confirm('确定要删除吗？', {icon: 0}, function (index, dd) {
                        top.mylayui.close(index);
                        vUser.deleteentity(data.userid);
                    });
                } else if (obj.event === 'edit') {
                    //layer.alert('编辑行：<br>'+ JSON.stringify(data))
                    //_this.OpTab(2,data);
                    //vUser.openadd(obj.data.userid);
                }
                else if (obj.event === 'btntz') {
                    vAttBmHz.openadd(obj.data.attsummaryid, obj.data.orgsummaryid, obj.data.userid);
                }
            });

            _table = table;
        })
    }

    function getData(callback) {
        $.ajax({
            type: "POST",
            url: "get_org_summary_Sh_list",
            data: {
                year: $('#year').val(),
                month: $('#month').val()
            },
            beforeSend: function (XHR) {

            },
            success: function (data) {
                data = eval('(' + data + ')').data;
                if (data.length > 0) {
                    window.orgsummaryid = data[0].orgsummaryid;
                    callback && callback(data[0]);


                } else {
                    callback && callback({});

                }

            },
            complete: function (XHR) {
                top.mylayui.closeAll('loading');
            },
            error: function () {

            }
        });

    }

    function search1() {

        _table.reload('attbmhzlist', {
            page: {
                curr: 1 //重新从第 1 页开始
            }
            ,
            where: {
                //year: $("#detailyear").val(),
                //mouth:$("#detailmonth").val(),
                year: data.year ? data.year : '1990',
                mouth: data.month,
                orgid: data.orgid,
                orgsummaryid: data.orgsummaryid,
                realname: $('#realname').val()
            }
        })
    }


    function search() {
        getData(function (data) {

            if(data.status == 4 || data.status == 2){
                $("#pdfbutton").show();
                $("#passbtn").hide();
                $("#retbtn").hide();

            }else if (data.status == 1){
                $('#pdfbutton').hide()
                $("#passbtn").show();
                $("#retbtn").show();
            }else{
                $('#pdfbutton').hide();
                $("#passbtn").hide();
                $("#retbtn").hide();
            }

            window.datas = data;
            if (data) {
                _table.reload('attbmhzlist', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,
                    where: {
                        //year: $("#detailyear").val(),
                        //mouth:$("#detailmonth").val(),
                        year: data.year ? data.year : '1990',
                        mouth: data.month,
                        orgid: data.orgid?data.orgid:"-1",
                        orgsummaryid: data.orgsummaryid,
                        realname: $('#realname').val()
                    }
                })
                testData();
            }

        })
    }

    function svg2canvas(targetElem) {
        var svgElem = targetElem.find('svg');
        svgElem.each(function (index, node) {
            var parentNode = node.parentNode;
            //由于现在的IE不支持直接对svg标签node取内容，所以需要在当前标签外面套一层div，通过外层div的innerHTML属性来获取
            var tempNode = document.createElement('div');
            tempNode.appendChild(node);
            var svg = tempNode.innerHTML;
            var canvas = document.createElement('canvas');
            //转换
            canvg(canvas, svg);
            parentNode.appendChild(canvas);
        });
    }

    function ok() {
        updateStatus(4, function () {
            createPdf();
            layer.msg('审核成功', {icon: 1})

        }, function () {
            layer.msg('审核失败', {icon: 0})

        })


    }

    function createPdf() {
        titlefomart();

        var orgname = $("#hidorgname").val();
        var date = new Date();
        var nowtime = $("#year").val() + "年" + date.getMonth() + 1 + "月" + date.getDate() + "日" + date.getHours() + "时" + date.getMinutes() + "分";
        var targetDom = $("#table");
        hidtablehight= targetDom.height();
        //水印生成
        watermark({watermark_txt: orgname + "  " + nowtime});

        //把需要导出的pdf内容clone一份，这样对它进行转换、微调等操作时才不会影响原来界面
        var copyDom = targetDom.clone();
        //新的div宽高跟原来一样，高度设置成自适应，这样才能完整显示节点中的所有内容（比如说表格滚动条中的内容）
        copyDom.width(targetDom.width() + "px");
        copyDom.height(targetDom.height() + "px");
        copyDom.css('display', 'block');
        copyDom.css({
            "background-color": "white",
            "position": "absolute",
            "top": "600px",
            "z-index": "-1",
            "height": targetDom.height()
        });
        $('body').append(copyDom);
        svg2canvas(copyDom);
        html2canvas(copyDom, {
            onrendered: function (canvas) {
                var imgData = canvas.toDataURL('image/jpeg');
                var img = new Image();
                img.src = imgData;

                // img.src = 'http://127.0.0.1:8080/1.pdf';
                //根据图片的尺寸设置pdf的规格，要在图片加载成功时执行，之所以要*0.225是因为比例问题
                img.onload = function () {
                    //此处需要注意，pdf横置和竖置两个属性，需要根据宽高的比例来调整，不然会出现显示不完全的问题
                    if (this.width > this.height) {
                        var doc = new jsPDF('l', 'mm', [this.width * 0.225,
                            this.height * 0.225
                        ]);
                    } else {
                        var doc = new jsPDF('p', 'mm', [this.width * 0.225,
                            this.height * 0.225
                        ]);
                    }
                    doc.addImage(imgData, 'jpeg', 0, 0, this.width * 0.225,
                        this.height * 0.225);
                    //根据下载保存成不同的文件名
                    var data = window.datas;
                    top.ShowZheZhao();
                    if (data.year) {
                        $.ajax({
                            type: "POST",
                            url: "createPDF",
                            data: {
                                file: doc.output("datauristring"),
                                year: data.year,
                                month: data.month,
                                orgid: data.orgid,

                            },
                            beforeSend: function (XHR) {

                            },
                            success: function (data) {


                            },
                            complete: function (XHR) {
                                top.ShowZheZhao();
                            },
                            error: function () {
                                top.ShowZheZhao();
                            }
                        });
                    }


                    // console.log(doc.output("datauristring"))
                    // doc.save('pdf_' + new Date().getTime() + '.pdf');
                };
                //删除复制出来的div
                copyDom.remove();
            },
            background: "#fff",

            //这里给生成的图片默认背景，不然的话，如果你的html根节点没设置背景的话，会用黑色填充。
            allowTaint: true //避免一些不识别的图片干扰，默认为false，遇到不识别的图片干扰则会停止处理html2canvas
        });
    }



    function watermark(settings) {
        //默认设置
        var defaultSettings = {
            watermark_txt: "text",
            watermark_x: 20,//水印起始位置x轴坐标
            watermark_y: 20,//水印起始位置Y轴坐标
            watermark_rows: 0,//水印行数,0表示动态获取
            watermark_cols: 20,//水印列数,0表示动态获取
            watermark_x_space: 100,//水印x轴间隔
            watermark_y_space: 50,//水印y轴间隔
            watermark_color: '#aaa',//水印字体颜色
            watermark_alpha: 0.9,//水印透明度
            watermark_fontsize: '15px',//水印字体大小
            watermark_font: '微软雅黑',//水印字体
            watermark_width: 240,//水印宽度
            watermark_height: 80,//水印长度
            watermark_angle: 15//水印倾斜度数
        };
        //采用配置项替换默认值，作用类似jquery.extend
        if (arguments.length === 1 && typeof arguments[0] === "object") {
            var src = arguments[0] || {};
            for (key in src) {
                if (src[key] && defaultSettings[key] && src[key] === defaultSettings[key])
                    continue;
                else if (src[key])
                    defaultSettings[key] = src[key];
            }
        }

        var oTemp = document.createDocumentFragment();

        //获取页面最大宽度
        var page_width = Math.max(document.body.scrollWidth, document.body.clientWidth);
        var cutWidth = page_width * 0.0150;
        var page_width = page_width - cutWidth;
        //获取页面最大高度
        var page_height = parseInt(hidtablehight);
        // var page_height = Math.max(document.body.scrollHeight, document.body.clientHeight) + 450;
        console.log("页面高度："+page_height);
        debugger;
        // var page_height = document.body.scrollHeight+document.body.scrollTop;
        //如果将水印列数设置为0，或水印列数设置过大，超过页面最大宽度，则重新计算水印列数和水印x轴间隔
        if (defaultSettings.watermark_cols == 0 || (parseInt(defaultSettings.watermark_x + defaultSettings.watermark_width * defaultSettings.watermark_cols + defaultSettings.watermark_x_space * (defaultSettings.watermark_cols - 1)) > page_width)) {
            defaultSettings.watermark_cols = parseInt((page_width - defaultSettings.watermark_x + defaultSettings.watermark_x_space) / (defaultSettings.watermark_width + defaultSettings.watermark_x_space));
            defaultSettings.watermark_x_space = parseInt((page_width - defaultSettings.watermark_x - defaultSettings.watermark_width * defaultSettings.watermark_cols) / (defaultSettings.watermark_cols - 1));
        }
        //如果将水印行数设置为0，或水印行数设置过大，超过页面最大长度，则重新计算水印行数和水印y轴间隔
        if (defaultSettings.watermark_rows == 0 || (parseInt(defaultSettings.watermark_y + defaultSettings.watermark_height * defaultSettings.watermark_rows + defaultSettings.watermark_y_space * (defaultSettings.watermark_rows - 1)) > page_height)) {
            defaultSettings.watermark_rows = parseInt((defaultSettings.watermark_y_space + page_height - defaultSettings.watermark_y) / (defaultSettings.watermark_height + defaultSettings.watermark_y_space));
            defaultSettings.watermark_y_space = parseInt(((page_height - defaultSettings.watermark_y) - defaultSettings.watermark_height * defaultSettings.watermark_rows) / (defaultSettings.watermark_rows - 1));
        }
        var x;
        var y;
        for (var i = 0; i < defaultSettings.watermark_rows; i++) {
            y = defaultSettings.watermark_y + (defaultSettings.watermark_y_space + defaultSettings.watermark_height) * i;
            for (var j = 0; j < defaultSettings.watermark_cols; j++) {
                x = defaultSettings.watermark_x + (defaultSettings.watermark_width + defaultSettings.watermark_x_space) * j;

                var mask_div = document.createElement('div');
                mask_div.id = 'mask_div' + i + j;
                mask_div.className = 'mask_div';
                mask_div.appendChild(document.createTextNode(defaultSettings.watermark_txt));
                //设置水印div倾斜显示
                mask_div.style.webkitTransform = "rotate(-" + defaultSettings.watermark_angle + "deg)";
                mask_div.style.MozTransform = "rotate(-" + defaultSettings.watermark_angle + "deg)";
                mask_div.style.msTransform = "rotate(-" + defaultSettings.watermark_angle + "deg)";
                mask_div.style.OTransform = "rotate(-" + defaultSettings.watermark_angle + "deg)";
                mask_div.style.transform = "rotate(-" + defaultSettings.watermark_angle + "deg)";
                mask_div.style.visibility = "";
                mask_div.style.position = "absolute";
                mask_div.style.left = x + 'px';
                mask_div.style.top = y + 'px';
                mask_div.style.overflow = "hidden";
                mask_div.style.zIndex = "9999";
                mask_div.style.pointerEvents = 'none';//pointer-events:none  让水印不遮挡页面的点击事件
                //mask_div.style.border="solid #eee 1px";
                mask_div.style.opacity = defaultSettings.watermark_alpha;
                mask_div.style.fontSize = defaultSettings.watermark_fontsize;
                mask_div.style.fontFamily = defaultSettings.watermark_font;
                mask_div.style.color = defaultSettings.watermark_color;
                mask_div.style.textAlign = "center";
                mask_div.style.width = defaultSettings.watermark_width + 'px';
                mask_div.style.height = defaultSettings.watermark_height + 'px';
                mask_div.style.display = "block";
                oTemp.appendChild(mask_div);
            }
            ;
        }
        ;
        // $("#table").appendChild(oTemp);
        document.getElementById("table").appendChild(oTemp);
    }


    function reject() {
        updateStatus(0, function () {
            layer.msg('驳回成功', {icon: 1})
        }, function () {
            layer.msg('驳回失败', {icon: 0})

        });
    }

    function updateStatus(status, success, fail) {

        $.ajax({
            type: "POST",
            url: "update_attstatus",
            data: {
                orgsummaryid: window.orgsummaryid,
                status: status,
            },
            beforeSend: function (XHR) {

            },
            success: function (data) {
                data = eval('(' + data + ')');
                if (data.code == 200) {
                    // updateApproverUser();//更新审批人
                    success && success();
                    search1()

                } else {
                    fail && fail();

                }

            },
            complete: function (XHR) {
                top.mylayui.closeAll('loading');
            },
            error: function () {

            }
        });
    }

    function updateApproverUser() {
        $.ajax({
            type: "POST",
            url: "update_approverUser",
            data: {
                orgsummaryid: window.orgsummaryid
            },
            beforeSend: function (XHR) {

            },
            success: function (data) {
                data = eval('(' + data + ')');
                if (data.code == 200) {
                    success && success();

                } else {
                    fail && fail();

                }

            },
            complete: function (XHR) {
                top.mylayui.closeAll('loading');
            },
            error: function () {

            }
        });
    }


</script>
</html>
